package leetcode.editor.cn;

/**
 * @author: yangwk
 * @date: 2023/10/18
 * @description:
 **/
public class P476 {
    public static void main(String[] args) {
        System.out.println(findComplement(10));
    }

    // (1*2^3+0*2^2+0*2^1+1*2^0)
    public static String toBinary(int num) {
        String sum = "";
        while (num != 0) {
            int reminder = num % 2;
            num /= 2;
            if (reminder == 1) {
                sum = 1 + sum;
            } else {
                sum = 0 + sum;
            }
        }
        return sum;
    }

    public static int findComplement(int num) {
        int sum = 0;
        int index = -1;
        while (num != 0) {
            int reminder = num % 2;
            index++;
            num /= 2;
            if (reminder == 0) {
                sum = sum + (int) Math.pow(2, index);
            }
        }
        return sum;
    }
}
